home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / CTools 2.2.1d / CTools / CTools.rsrc / TEXT_151_Nesters.txt < prev    next >
Encoding:
Text File  |  1995-12-01  |  4.1 KB  |  80 lines

  1. Nested Routines
  2.  
  3. The only remaining preventer of all routines showing up in the popup are Pascals lovely "nested functions" thingy.  These are fairly easy to fix.  Sometimes they can be quite complex.
  4.  
  5. In the Function Pop Up, one of these will be the bottom routine on the list.  They are identified by a start brace but then a complete routine after the variables are declared.  Here‚Äôs an example from ‚ÄúIcosahedron‚Äù:
  6.  
  7. In the Pascal to C output, it‚Äôs:
  8.  
  9. // The primary routine beginning.
  10. void Shadefaces()
  11. {                        // You have to add this brace.
  12.     short ThisFace;      // These variables...
  13.     RgnHandle aRegion;   // ...do not appear...
  14.     short Level;         // ...in the nested routine.
  15.  
  16.     // Nested routine begins here.
  17.     double Bright (Coordinates PlaneNorm, Coordinates LightNorm)
  18.     {
  19.         Bright = ((PlaneNorm[1] * LightNorm[1] +
  20.                    PlaneNorm[2] * LightNorm[2] + 
  21.                    PlaneNorm[3] * LightNorm[3]) + 1.0) / 2.0
  22.     }    // End of nested routine.
  23.  
  24. {    // Begin of primary routine.
  25.     aRegion = NewRgn();  // First used from primary variables.
  26.     for (ThisFace = 0; ThisFace < kNumFaces; ThisFace++)
  27.     {
  28.     [snip]
  29.         level = ceil(Bright(Normal, light) * 64.0);
  30.     [snip]
  31.     }
  32. }    //‚Ä¢ Shadefaces.    // End of primary routine.
  33.  
  34. Select the part above the complete routine and copy it.  In CMaster, hit your hot-keys (or tool icon) to comment this out.
  35.  
  36. // void Shadefaces()
  37. // {
  38. //     short ThisFace;      // These variables...
  39. //     RgnHandle aRegion;   // ...do not appear...
  40. //     short Level;         // ...in the nested routine.
  41.  
  42. Now, scroll down until you find the actual start of that copied routine declaration with variables.  There'll be a start brace right after an end brace.  Depending on how many functions are nested within it, the first one of these you find may or may not be where that goes.  Sometimes the author of the Pascal code marks it with a comment (hopefully).  Anyway, wherever you find it, select the start brace, hit RETURN and then paste the declaration and variables.
  43.  
  44. In our example, here‚Äôs what you end up with:
  45.  
  46. // UN-Nested routine begins here.
  47. double Bright (Coordinates PlaneNorm, Coordinates LightNorm)
  48. {
  49.     Bright = ((PlaneNorm[1] * LightNorm[1] +
  50.                PlaneNorm[2] * LightNorm[2] + 
  51.                PlaneNorm[3] * LightNorm[3]) + 1.0) / 2.0
  52. }    // End of nested routine.
  53.  
  54. // The primary routine beginning.
  55. void Shadefaces()
  56. {                        // You have to add this brace.
  57.     short ThisFace;      // These...
  58.     RgnHandle aRegion;   // ...do not appear...
  59.     short Level;         // ...in the nested routine.
  60.                          // Where original ‚Äúbegin‚Äù was.
  61.     aRegion = NewRgn();  // First used from primary variables.
  62.     for (ThisFace = 0; ThisFace < kNumFaces; ThisFace++)
  63.     {
  64.     [snip]
  65.         level = ceil(Bright(Normal, light) * 64.0);
  66.     [snip]
  67.     }
  68. }    //‚Ä¢ Shadefaces.    // End of primary routine.
  69.  
  70. One way you can find them is to look in the variables in the ‚Äúprimary header declaration‚Äù (which you copied and commented out) and find the first occurrence of its use, following it.  There will often be one that is unique to the body of the routine where that declaration goes.  In the example, Bright did not contain ThisFace, aRegion or Level, so you can find the ‚Äúnest‚Äù with those as search strings.  The next occurrence of one of these variables beyond its original location, where there‚Äôs a ‚Äò}‚Äô followed by a ‚Äò{‚Äò just above it, will be where the primary function beginning goes.
  71.  
  72. If there are several nested routines, the first set of variables may belong to more than one of them.  You don‚Äôt need to be concerned about those until compile time.  A decision will have to be made whether to make several locals or all of those global, at that time.
  73.  
  74. Now check the Function Pop Up.
  75.  
  76. So, you just repeat these steps until ALL routines show in the popup.  The last routine - main () - will not be declared.  You‚Äôll have to type in the declaration yourself.  Pascal programmers usually mark this well.
  77.  
  78. The last brace of the program file (end of ‚Äúmain‚Äù) has a dot after it which you may as well remove while you‚Äôre there.
  79.  
  80.